import ReactDOM from 'react-dom/client';
import './index.css';

const messageRoot = ReactDOM.createRoot(document.getElementById('message-view'));

export function message(title, content, time = 1000) {
  if(message.__timer){
    clearTimeout(message.__timer);
  }
  messageRoot.render(<div className="message-container">
    <div className="message-view">
      <div className="message-title">{title}</div>
      <div className="message-content">{content}</div>
    </div>
  </div>);
  message.__timer = setTimeout(() => {
    messageRoot.render(''); // 不建议使用卸载，卸载后还要继续
  }, time);
}
